<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Jcc\LaravelVote\Vote;
use JWTAuth;
use Overtrue\LaravelFollow\Traits\CanFavorite;
use Overtrue\LaravelFollow\Traits\CanFollow;
use Overtrue\LaravelFollow\Traits\CanLike;
use Overtrue\LaravelFollow\Traits\CanSubscribe;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;

/**
 * Class User
 * @package App
 * @mixin \Eloquent
 */
class User extends Authenticatable
{
    use Notifiable, Vote, CanFollow, CanLike, CanFavorite, CanSubscribe;
    protected $guarded = [];

    protected $primaryKey = "id";

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */


    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * @return bool|mixed
     */
    public static function isLogin()
    {
        try {
            if (!$user = JWTAuth::parseToken()->authenticate()) {
                $user = false;
            }
        } catch (TokenExpiredException $e) {
            $user = false;
        } catch (TokenInvalidException $e) {
            $user = false;
        } catch (JWTException $e) {
            $user = false;
        }

        return $user;
    }
}
